#include "process_pool.h"

#define FILENAME "small_file.txt"

int transferFile(int peerfd)
{
    //读取本地文件
    int fd = open(FILENAME, O_RDONLY);
    ERROR_CHECK(fd, -1, "open");
    char buff[100] = {0};
    int filelength = read(fd, buff, sizeof(buff));
    ERROR_CHECK(filelength, -1, "read");

    //进行发送操作
    //1. 发送文件名
    train_t t;
    memset(&t, 0, sizeof(t));
    t.len = strlen(FILENAME);
    strcpy(t.buf, FILENAME);
    send(peerfd, &t, 4 + t.len, 0);
    
    //2. 再发送文件内容
    memset(&t, 0, sizeof(t));
    t.len = filelength;
    strncpy(t.buf, buff, t.len);
    send(peerfd, &t, 4 + t.len, 0);

    return 0;
}

